from io import BytesIO

from minio import Minio, S3Error

# # 这是内网服务器的
# client = Minio(
#     endpoint="127.0.0.1:9000",
#     access_key="wr8s9pEfDZu5j6k8qnwB",
#     secret_key="vaUescIBViPyek84IF3abRUvkEMRALwAkxkAzA2t",
#     secure=False  # 如果使用HTTPS，则设置为True
# )

# 这是测试服务器的
client = Minio(
    endpoint="10.105.10.193:9000",
    access_key="vIDqbXGCUUO2qkAgpF5A",
    secret_key="Lk8Yu4A9JOPCsGHhRJHDCpbEGy4WHCPiYiazPujm",
    secure=False  # 如果使用HTTPS，则设置为True
)
# 这是假期测试服务器
# client = Minio(
#     endpoint="150.158.135.236:9000",
#     access_key="b74FWubQGNXZZQZyN2mP",
#     secret_key="pq1dEmUUqvcQA2HTlPX9KG9CXIDTz088SgaOXqsw",
#     secure=False  # 如果使用HTTPS，则设置为True
# )
#



# 文件上传
def putObject(bucket_name: str, object_name: str, file: BytesIO):
    try:
        client.put_object(
            bucket_name,
            object_name,
            file,
            length=file.getbuffer().nbytes,
            content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        )
        print(f"成功上传 {object_name} 到 {bucket_name}")
    except S3Error as e:
        print(f"上传 {object_name} 时出错: {e}")
